--------------------------------------------------
-- 脚本名称: 2345_install
-- 脚本描述: 

-- 体验应用
-- 恢复出厂
-- 清除数据
-- 配置系统
-- 安装2345

--------------------------------------------------

ipFile = "/sdcard/123.txt"

-- 脚本入口
function main()

	if app.isinstall("com.market2345") then
		mainTask()
		sleep(math.random(6,8)*60*60*1000)
		mainTask()
		sleep(math.random(6,8)*60*60*1000)
		mainTask()
		sleep(math.random(6,8)*60*60*1000)
		os.execute("reboot")
	else
		checkXposed()
		checkId()
		install2345()
		installApps()	
	end	
end


-- 检测Xposed是否安装
function checkXposed()
	-- com.example.myxposed
	-- de.robv.android.xposed.installer

	if app.isinstall("com.example.myxposed") then
	else
		toast("安装 xposed")
		app.install("xposed.apk")
		app.install("myxposed.apk")
		--[[
		for i=60*5,1,-5 do
			if app.isinstall("com.example.myxposed") then
				i=0
				toast("安装完成")
			end
			sleep(5*1000)
		end
		]]
	end
end

-- 检测ID是否更改
function checkId()
end

-- 安装2345应用商店
function install2345()
	app.start("com.android.browser")
	sleep(3*1000)
	touch.click(177,88)
	sleep(1000)
	ime.inputText("http://2345.cn/k15932379")
	sleep(500)
	key.enter()
	sleep(1000)
	touch.click(353,752)
	sleep(5*1000)
	touch.click(520,1206)
	
	for i=60*5,1,-3 do
		isFound,x,y,tb = find.colors({
			0xFFFFFF,
			{9,-7,0x737373},
			{18,15,0x737373},
			{34,-7,0x737373},
			{48,14,0x747474},
			{50,-2,0xFFFFFF}},95,485,1184,564,1220)

		if (isFound) then
			touch.click(x+5, y+5)
		end
		if app.isinstall("com.market2345") then
			app.start("com.market2345")
			i=0
		end
		sleep(3000)
	end
end

-- 安装其他应用
function installApps()
end

app_list={  "com.market2345",
			"cn.etouch.ecalendar",
			"cn.jj",
			"cn.kuwo.player",
			"com.autonavi.minimap",
			"com.baidu.searchbox",
			"com.book2345.reader",
			"com.browser2345",
			"com.cleanmaster.mguard_cn",
			"com.happyelements.AndroidAnimal",
			"com.iflytek.inputmethod",
			"com.jingdong.app.mall",
			"com.qihoo.browser",
			"com.qihoo360.mobilesafe",
			"com.sankuai.meituan",
			"com.ss.android.article.news",
			"com.storm.smart",
			"com.tencent.mm",
			"com.tencent.news",
			"com.tencent.qqlive",
			"com.tencent.reading",
			"com.tianqi2345",
			"com.UCMobile",
			"sogou.mobile.explorer",
			""}		

function mainTask()
	os.execute("ifconfig wlan0 | cut -d : -f 2 | cut -d ' ' -f 3 > " .. ipFile)
	local file,errMsg = io.open(ipFile,"rb")
	if file then
		net.get("http://www.yejopang.com/2345/set.php?ip=" .. file:read(), 3)  
		file:close() --> 关闭文件
	else
		print("打开失败,原因:" .. errMsg)
	end
ii=1
while (app_list[ii]~=nil) do
	isinstalled = app.isinstall(app_list[ii])
	if isinstalled then
		app.start(app_list[ii])
		enjoy(app_list[ii])
		app.stop(app_list[ii])
		app.killall()
	end
	
    ii=ii+1
end
end

function enjoy(appName)
	for i=60*5,1,-10 do
	toast("enjoy "..appName.." more \n\n      "..i.." s")
    sleep(math.random(3,7)*1000)
	touch.swipe(math.random(100,600), math.random(100,1000),math.random(100,600),math.random(100,1000))
	sleep(math.random(3,7)*1000)
	end
end

-- 此行无论如何保持最后一行
main()
